/**
 * @description  场景管理器
 */
export default class SceneManager{
    constructor(){
        this.scenes = new Map(); //初始化场景集合
        this.currentSceneName = null; //当前场景名
    }

    /**
     * @description 生成场景名
     * @returns {string}
     */
    generateSceneName(){
        return "scene" + (this.scenes.size+ 1);
    }

    /**
     * @description 添加场景
     * @param scene
     * @returns {string}
     */
    addScene(scene){
        let name = this.generateSceneName();
        this.scenes.set(name,{scene});
        return name;
    }

    /**
     * @description 删除场景
     * @param sceneName
     */
    removeScene(sceneName){
        this.scenes.delete(sceneName);
    }

    /**
     * @description 设置当前场景名称
     * @param sceneName
     */
    setCurrentSceneByName(sceneName){
        this.scenes.entries().forEach(([key,value])=>{
            if (key === sceneName){
                value.renderer.domElement.style.display = 'block';
            }else {
                value.renderer.domElement.style.display = 'none';
            }
        })
        this.currentSceneName = sceneName;
    }
    getScene(sceneName){
        return this.scenes.get(sceneName).scene;
    }
    getCurrentSceneName(){
        return this.currentSceneName;
    }
    getCurrentScene(){
        return this.scenes.get(this.currentSceneName).scene;
    }
    setCameraToScene(sceneName,camera){
        let value = this.scenes.get(sceneName);
        if (value){
            value.camera = camera;
            this.scenes.set(sceneName,value);
        }
    }

    getCurrentSceneCamera(){
        return this.scenes.get(this.currentSceneName).camera;
    }
    setControlsToScene(sceneName,controls){
        let value = this.scenes.get(sceneName);
        if (value){
            value.control = controls;
            this.scenes.set(sceneName,value);
        }
    }
    getCurrentSceneControls(){
        return this.scenes.get(this.currentSceneName).control;
    }

    /**
     * 设置场景的渲染器
     * @param sceneName
     * @param renderer
     */
    setRendererToScene(sceneName,renderer){
        let value = this.scenes.get(sceneName);
        if (value){
            value.renderer = renderer;
            this.scenes.set(sceneName,value);
        }
    }

    /**
     * 获取场景的渲染器
     * @returns {*}
     */
    getCurrentSceneRenderer(){
        return this.scenes.get(this.currentSceneName).renderer;
    }

    getCamera(sceneName){
        return this.scenes.get(sceneName).camera;
    }

}